﻿namespace Vibstudio.NetConfigurator.UI.Model
{
    #region Namespaces

    using System.Collections.Generic;
    using System.Linq;

    using Vibstudio.NetConfigurator.Model;

    #endregion

    public sealed class ResultValidationFileCollection : ResultCollectionBase<ResultValidationFile>
    {
        #region Ctor(s)

        public ResultValidationFileCollection(IEnumerable<ResultValidation<ConfigurationFile>> collection)
            : base(AdaptResult(collection))
        {
        }

        #endregion

        #region Public Properties

        public static bool IsValid { get; private set; }

        #endregion

        #region Methods

        private static IEnumerable<ResultValidationFile> AdaptResult(
            IEnumerable<ResultValidation<ConfigurationFile>> collection)
        {
            List<ResultValidationFile> result =
                collection.Select(r => new ResultValidationFile(r.Owner, r.IsValid, r.Message)).ToList();

            IsValid = true;
            foreach (ResultValidationFile validationFile in result)
            {
                if (!validationFile.IsValid)
                {
                    IsValid = false;
                    break;
                }
            }

            return result;
        }

        #endregion
    }
}